/**
 *
 */
var path = '../';
var pageListUrl = path + 'appInfo/list';
var pageUrl = path + 'appInfo/';

// ---------------交互代码begin-----------------
//本页面业务逻辑
var dictType={
    checkLogic:function(dataObj){
        var result="";
        var isSubmit=true;
        //TODO 逻辑校验 eg:
        if($("#file")[0].files.length < 1){
            dataObj.appNameErr = "请选择要上传的APK文件";
            isSubmit=false;
        }else {
            var fileName = $("#file")[0].files[0].name;
            var fileType = fileName.substr(fileName.lastIndexOf(".") + 1,fileName.length);
            if(fileType.toUpperCase() != 'APK'){
                dataObj.appNameErr = "请上传*.apk应用程序";
                isSubmit=false;
            }
        }

        result=customUtils.checkLen(dataObj.version,1,16,'版本号');
        if(result.length!=0){
            dataObj.versionErr=result;
            isSubmit=false;
        }

        result=customUtils.checkLen(dataObj.version,1,16,'版本号');
        if(result.length!=0){
            dataObj.versionErr=result;
            isSubmit=false;
        }

        if(!dataObj.version.match("([0-9])\\.([0-9])\\.([0-9])")){
            dataObj.versionErr='请输入正确的版本号如：1.0.1';
            isSubmit=false;
        }

        if(dataObj.firmwareStatus==""){
            dataObj.firmwareStatusErr='请选择升级类型：如不选择默认为普通升级';
            dataObj.firmwareStatus='0';
            isSubmit=false;
        }

        $.ajax({
            url : pageUrl + "checkVersion",
            type : "POST",
            dataType: "json",
            data : {
                version:dataObj.version,
                appName:$("#file")[0].files[0].name.substr(0,fileName.lastIndexOf("."))
            },
            cache:false ,
            async: false
        }).done(function(res) {
            if(res.result=='1'){
                dataObj.versionErr='版本号已经存在';
                isSubmit=false;
            }
        })
        return isSubmit;
    },
    checkFileType:function () {
        var fileName = $("#filed")[0].files[0].name;
        var fileType = fileName.substr(fileName.lastIndexOf(".") + 1,fileName.length);
        if(fileType.toUpperCase() != 'XLSX' && fileType.toUpperCase() != 'XLS'){
            importVue.fileErr = "请选择*.xlsx或者*.xls格式的Excel文件";
            return false;
        }
        return true;
    }

};

//绑定列表List---begin----所有的操作都围绕列表展开，新增、更新其他比较独立
var dataList=new Vue({
    el:"#appInfoList",
    data:{
        pageInfo : {},
        //自定义条件查询---begin--------

        //自定义条件查询---end--------
        selectIds:[],//多选
        selectedIdx:-1,//保存操作行的索引
        eventSrc:"",//init:页面初始化；search:点击查询；paging:点击翻页；changePageSize:改变页面显示条数
        selectedPageSize:customUtils.pageSize//修改页面数据显示条数
    },
    mounted: function () {
        //初始化页面数据
        //this.getAreaData();
        this.getList('init');
    },
    // 在 `methods` 对象中定义方法,如果操作中函数的逻辑比较复杂，必须封装到dictType对象
    methods:{
        showPostions:function (index) {
            var record = this.pageInfo.list[index];
            this.$http.get(pageUrl + "show/" + record.postionCodeList).then(function (response) {
                console.log(response.body)
                showVue.$data.provinces = response.body.tree;
                showVue.showPostions();
            })
        },
        selectChkBtn:function(e){//用于多选事件
            this.selectIds.push($(e.target).val());
        },
        getAreaData:function () {
            this.$http.get("../appInfo/tree").then(function(response){
                console.log(response);
                addOrUpdate.$data.provinces = response.body;
                console.log(addOrUpdate.$data)
            },function (res) {
                customUtils.showRequestTips(res,2000)
            });
        },
        //搜索、分页列表
        getList:function(eventSrc){
            //保存事件源
            this.eventSrc=eventSrc;
            //改变页面显示条数
            if(eventSrc=="changePageSize"){
                if(this.pageInfo.pageSize != this.selectedPageSize){
                    this.pageInfo.pageSize=this.selectedPageSize;
                    $('#pagination').jqPaginator('destroy');
                    eventSrc='init';//重新绘制控件
                }else{
                    return;
                }
            }
            var param = {"page":1,"rows":customUtils.pageSize};
            //初始化时无当前页数，后台有默认第1页，每页10条
            if(this.pageInfo!=undefined && this.pageInfo.pageNum!=undefined){
                param["page"]=this.pageInfo.pageNum;
                param["rows"]=this.pageInfo.pageSize;
            }

            this.$http.post(pageListUrl,param).then(function(response){
                dataList.pageInfo = response.body.pagination;
                customUtils.noData('无数据',dataList.pageInfo.pages);
                //页面初始化、搜索时，才需要执行分页控件
                if(eventSrc=='init' || eventSrc=='search'){
                    customUtils.paging('#pagination',dataList.pageInfo.pages,customUtils.showPage,function(num){
                        //当前页码pageNum与将要翻页的页码num不相等才执行，否则为同一页
                        if(dataList.pageInfo.pageNum!=num){
                            dataList.pageInfo.pageNum=num;
                            dataList.getList('paging');
                        }
                    });
                }
            },function(response){
                console.log(response.body);
            });
        },
        //更新状态
        updateStatus:function(index){
            var record = this.pageInfo.list[index];
            var status = record.status==1?0:1;
            var param = {id:record.id,status:status};
            this.$http.post(pageUrl + 'update',param).then(function(response){
                record.status=status;
                this.getList("init");
                customUtils.showTips(response.body,null,1000);
            },function(response){
                console.log(response.body);
            });
        },

        //更新状态
        updateStatus1:function(index){
            var record = this.pageInfo.list[index];
            var updateStatus = record.updateStatus==1?0:1;
            var param = {id:record.id,updateStatus:updateStatus};
            this.$http.post(pageUrl + 'updateVe',param).then(function(response){
                record.updateStatus=updateStatus;
                this.getList("no");
                customUtils.showTips(response.body,null,1000);
            },function(response){
                console.log(response.body);
            });
        },//删除App
        deleteApp:function(index){
            var record = this.pageInfo.list[index];
            var param = {id:record.id};
            this.$http.post(pageUrl + 'delete',param).then(function(response){
                customUtils.showTips(response.body,null,3000);
                this.getList("no");
            },function(response){
                console.log(response.body);
            });
        },

        clear:function (arr) {
            arr.splice(0,arr.length);
        },
        //初始化更新，更新对话框
        updateInit:function(index){
            var record = this.pageInfo.list[index];
            this.selectedIdx=index;
            var url = pageUrl + 'id/'+record.id;
            this.$http.get(url).then(function(response){
                //解析得到已选中的项
                addOrUpdate.$data.codes = [];
                addOrUpdate.$data.codes = JSON.parse(response.body.postionCodeList);
                //
                dataList.clear(addOrUpdate.$data.checkPostions);
                dataList.clear(addOrUpdate.$data.checkProvinces);
                dataList.clear(addOrUpdate.$data.checkCitys);
                dataList.clear(addOrUpdate.$data.checkAreas);
                $.each(addOrUpdate.$data.provinces,function (p) {
                    var pNum = 0;
                    $.each(addOrUpdate.$data.provinces[p].citys,function (c) {
                        var cNum = 0;
                        $.each(addOrUpdate.$data.provinces[p].citys[c].areas,function (a) {
                            var aNum = 0;
                            $.each(addOrUpdate.$data.provinces[p].citys[c].areas[a].postions,function (i) {
                                var postion = addOrUpdate.$data.provinces[p].citys[c].areas[a].postions[i];
                                if($.inArray(postion.postionCode, addOrUpdate.$data.codes) != '-1'){
                                    addOrUpdate.$data.checkPostions.push(postion);
                                    aNum++;
                                    cNum++;
                                    pNum++;
                                }
                            })
                            if(aNum > 0) {
                                console.log(addOrUpdate.$data.provinces[p].citys[c].areas[a].name)
                                console.log(aNum)
                                addOrUpdate.$data.checkAreas.push(addOrUpdate.$data.provinces[p].citys[c].areas[a])
                            }
                        })
                        if( cNum > 0) {
                            console.log(addOrUpdate.$data.provinces[p].citys[c].name)
                            console.log(cNum)
                            addOrUpdate.$data.checkCitys.push(addOrUpdate.$data.provinces[p].citys[c]);
                        }
                    })
                    if(pNum > 0){
                        console.log(addOrUpdate.$data.provinces[p].name)
                        console.log(pNum)
                        addOrUpdate.$data.checkProvinces.push(addOrUpdate.$data.provinces[p]);
                    }
                })

                //回显表单数据
                $.each(response.body, function(key) {
                    if(addOrUpdate[key]!=undefined){
                        addOrUpdate[key] = response.body[key];
                    }
                });
                console.log(addOrUpdate.$data)
            },function(response){
                console.log(response);
                customUtils.showRequestTips(response,3000);
            });

            this.addOrUpdatePanel("update");

        },
        importPostion:function(index){
            console.log(index);
            var record = this.pageInfo.list[index];

            importVue.$data.appVersionId=record.appVersionId
            console.log(importVue.$data.appVersionId);

            var obj3 = document.getElementById('file') ;
            obj3.outerHTML=obj3.outerHTML;
            importVue.fileErr = "";
            importPanel = layer.open({
                type : 1,
                title :"导入位置信息",
                area : [ '600px', '70%' ],
                shadeClose : false, // 点击遮罩关闭
                content : $('#importPanel')
            });
        },
        importVersion:function(index){
            console.log(index);
            var record = this.pageInfo.list[index];

            importPanelVue.$data.appVersionId=record.appVersionId
            console.log(importVue.$data.appVersionId);

            var obj3 = document.getElementById('file') ;
            obj3.outerHTML=obj3.outerHTML;
            importVue.fileErr = "";
            importPanel1 = layer.open({
                type : 1,
                title :"导入App版本信息",
                area : [ '600px', '70%' ],
                shadeClose : false, // 点击遮罩关闭
                content : $('#importPanel1')
            });
        },
        importVersionList:function(index){
            console.log(index);
            var record = this.pageInfo.list[index];

            importPanelListVue.$data.appVersionId=record.appVersionId
            console.log(importVue.$data.appVersionId);

            var obj3 = document.getElementById('file') ;
            obj3.outerHTML=obj3.outerHTML;
            importVue.fileErr = "";
            importPanel2 = layer.open({
                type : 1,
                title :"导入过渡版本信息",
                area : [ '600px', '70%' ],
                shadeClose : false, // 点击遮罩关闭
                content : $('#importPanel2')
            });
        },
        importUpdateVersion:function(index){
            console.log(index);
            var record = this.pageInfo.list[index];
            importUpdatePanelListVue.$data.appVersionId=record.appVersionId
            console.log(importVue.$data.appVersionId);
            var obj3 = document.getElementById('file') ;
            obj3.outerHTML=obj3.outerHTML;
            importVue.fileErr = "";
            importPanel3 = layer.open({
                type : 1,
                title :"导入App版本信息",
                area : [ '600px', '70%' ],
                shadeClose : false, // 点击遮罩关闭
                content : $('#importPanel3')
            });
        },
        importFirmwareList:function(index){
            console.log(index);
            var record = this.pageInfo.list[index];
            importFirmwarePanelListVue.$data.appVersionId=record.appVersionId
            console.log(importVue.$data.appVersionId);
            var obj3 = document.getElementById('file') ;
            obj3.outerHTML=obj3.outerHTML;
            importVue.fileErr = "";
            importPanel4 = layer.open({
                type : 1,
                title :"导入固件App版本信息",
                area : [ '600px', '70%' ],
                shadeClose : false, // 点击遮罩关闭
                content : $('#importPanel4')
            });
        },
        //打开添加对话框
        addOrUpdatePanel:function(flag){
            var title;
            //拿到所有位置数据
            if(flag=="update"){
                title = "修改App更新区域"
                //表单属性设置
                $("#t1").hide();
                $("#t3").show();
                $("#t2").find("input[name='version']").attr("readonly",true);
            }else{
                title = "添加App"
                //表单属性设置
                $("#t1").show();
                $("#t3").hide();
                $("#t2").find("input[name='version']").attr("readonly",false);
                //取消选中
                addOrUpdate.$data.codes = [];
                //清除表单数据
                addOrUpdate.$data.version="";
                addOrUpdate.$data.id = "";
                addOrUpdate.$data.checkPostions = [];
                addOrUpdate.$data.checkProvinces = [];
                addOrUpdate.$data.checkCitys = [];
                addOrUpdate.$data.checkAreas = [];
            }
            var obj3 = document.getElementById('file') ;
            obj3.outerHTML=obj3.outerHTML;
            //删除错误信息
            $.each(addOrUpdate.$data,function (key) {
                if(key.substring(key.length-3,key.length) == 'Err'){
                    addOrUpdate.$data[key] = "";
                }
            })



            //树形收缩
            $(".citys").hide();
            $(".areas").hide();
            $(".postions").hide();

            console.log(addOrUpdate.$data);
            addPanel = layer.open({
                type : 1,
                title : title,
                area : [ '570px', '400px' ],
                shadeClose : false, // 点击遮罩关闭
                content : $('#addPanel')
            });
        }
    },

});
//绑定列表List---end----

//添加弹窗
var addPanel = null;

var treeFunction = {
    choiceProvince:function (fg,province) {
        for(var i = 0; i < province.citys.length; i++) {
            //选中子项
            treeFunction.choiceItem(fg,addOrUpdate.$data.checkCitys,province.citys[i]);
            //往下传递--选中
            treeFunction.choiceCity(fg,province.citys[i]);
        }
    },
    choiceCity:function (fg,city) {
        for(var i = 0; i < city.areas.length; i++) {
            //选中子项
            treeFunction.choiceItem(fg,addOrUpdate.$data.checkAreas,city.areas[i]);
            //往下传递--选中
            treeFunction.choiceArea(fg,city.areas[i]);
        }
    },
    choiceArea:function(fg,area){
        for(var i = 0; i < area.postions.length; i++) {
            //选中子项
            treeFunction.choiceItem(fg,addOrUpdate.$data.checkPostions,area.postions[i]);
            //往下传递--选中
            treeFunction.choicePostion(fg,area.postions[i]);
        }
    },
    choicePostion:function (fg,postion) {

    },
    //避免重复添加--比较字段 val.code  ,postionCode
    pushNoRepeat:function(arr,val){
        var fg = true;
        for (var i = 0; i< arr.length; i++){
            if((val.code && arr[i].code == val.code) || (val.postionCode && val.postionCode == arr[i].postionCode) ){
                fg = false;
                break;
            }
        }
        if(fg){
            arr.push(val);
        }
    },
    //选择某一项--添加或删除
    choiceItem:function (fg,arr,val) {
        if(fg){
            treeFunction.pushNoRepeat(arr,val);
        }else{
            if("-1" != $.inArray(val, arr)){
                arr.splice($.inArray(val, arr), 1);
            }
        }
    },
    //往数组添加或删除数据。添加不重复,并且返回一个新的数组，
    addOrRemove:function (fg,arr,val) {
        var newArr = [];
        $.each(arr,function (i) {
            newArr[i] = arr[i];
        });
        if(fg){
            treeFunction.pushNoRepeat(newArr,val);
        }else{
            newArr.splice($.inArray(val, newArr), 1);
        }
        return newArr;
    },
    //根据code 计算差异元素
    difference:function (val,oldVal) {
        var many = val.length > oldVal.length ? val : oldVal;
        var less = val.length < oldVal.length ? val : oldVal;
        var result = "";
        $.each(many,function (i) {
            if('-1' == $.inArray(many[i], less)) {
                result =  many[i];
                return;
            }
        });
        return result;
    }

}



//新增或更新---------begin-------
var addOrUpdate = new Vue({
    el:"#addPanel",
    data:{
        id:"",
        appName: "",
        version:"",
        firmwareStatus:"0",
        appFile:"",
        status:"",
        updateStatus:"",
        postionCodeList:"",
        codes:[],
        //所有数据源头
        provinces:[],
        //选中的数据
        checkProvinces:[],
        checkCitys:[],
        checkAreas:[],
        checkPostions:[],
        diff:"",
        //提示信息
        returnCode:"",
        msg:"",
        //以下是错误信息，后面优化为插件vee-validator
        versionErr:"",
        firmwareStatusErr:"",
        appNameErr:"",
        appVersionIdErr:""
    },
    watch: {
        checkProvinces:{
            handler:function(val,oldVal){
                if(val.length == oldVal.length){
                    //修改数据出发的事件---不处理
                    return;
                }
                var province = treeFunction.difference(val,oldVal);
                var fg = val.length > oldVal.length;
                treeFunction.choiceProvince(fg,province);
            },
            deep:true
        },
        checkCitys:{
            handler:function (val,oldVal) {
                if(val.length == oldVal.length){
                    //修改数据出发的事件---不处理
                    return;
                }
                var city = treeFunction.difference(val,oldVal);
                var fg = val.length > oldVal.length;
                treeFunction.choiceCity(fg,city);
            },
            deep:true
        },

        checkAreas:{
            handler:function (val,oldVal) {
                if(val.length == oldVal.length){
                    //修改数据出发的事件---不处理
                    return;
                }
                var area = treeFunction.difference(val,oldVal);
                var fg = val.length > oldVal.length;
                treeFunction.choiceArea(fg,area);                },
            deep:true
        },

        checkPostions:{
            handler:function (val,oldVal) {
                if(val.length == oldVal.length){
                    //修改数据出发的事件---不处理
                    return;
                }
                var postion = treeFunction.difference(val,oldVal);
                var fg = val.length > oldVal.length;
                treeFunction.choicePostion(fg,postion)
            },
            deep:true
        }
    },
    methods:{
        changeTime:function(elem){
            addOrUpdate.updatedDate = $("#"+elem).val();
        },
        hsCitys:function (event) {
            var clickElement = event.currentTarget;
            $($(clickElement).parent().find(".citys")[0]).toggle();
        },
        hsAreas:function (event) {
            var clickElement = event.currentTarget;
            $($(clickElement).parent().find(".areas")[0]).toggle();
        },
        hsPostions:function(event,area){
            var clickElement = event.currentTarget;
            var postions = $(clickElement).parent().find(".postions")[0];
            $(postions).toggle();
        },
        checkAll:function (event,obj) {
            var clickElement = event.currentTarget;
            var fg = $(clickElement).prop("checked");
            console.log(addOrUpdate.$data)
            //区域全选/
            if(obj && obj.type == 'region_area'){
                $.each(obj.postions,function(i){
                    addOrUpdate.addOrRemove(fg,addOrUpdate.$data.codes,obj.postions[i].code);
                });
            }else if(obj && obj.type == 'region_city'){
                //市全选
                $.each(obj.areas,function (i) {
                    addOrUpdate.checkAreaPostion(fg,obj.areas[i]);
                });
                //勾上区的全选按钮
                $.each(obj.areas,function(i){
                    addOrUpdate.pushNoRepeat(addOrUpdate.aCodes,obj.areas[i].code)
                });
            }else if(obj && obj.type == 'region_province'){
                // 省全选
                $.each(obj.citys,function (i) {
                    $.each(obj.citys[i].areas,function (j) {
                        addOrUpdate.checkAreaPostion(fg,obj.citys[i].areas[j]);
                    });
                });

                $.each(obj.citys,function(i){
                    //勾选上市
                    addOrUpdate.pushNoRepeat(addOrUpdate.cCodes,obj.citys[i].code)
                    $.each(obj.citys[i].areas,function(j){
                        //勾选上区
                        addOrUpdate.pushNoRepeat(addOrUpdate.aCodes,obj.citys[i].areas[j].code);
                    });

                });

            }
        },

        upload:function (e) {
            console.log(this.id)
            if(this.id==""){
                // 错误信息清除
                addOrUpdate.$data.appNameErr="";
                addOrUpdate.$data.versionErr="";
                addOrUpdate.$data.appVersionIdErr="";
                //逻辑校验
                if(!dictType.checkLogic(this.$data)){
                    return;
                }
                var formDate = new FormData($("#addPanel")[0]);
                console.log(formDate);
                var loading = layer.load(0, {shade: [0.5,'#949494']});
                $.ajax({
                    url : pageUrl + "upload",
                    type : "POST",
                    dataType: "json",
                    cache: false,
                    data : formDate,
                    processData: false,
                    contentType: false
                }).done(function(res) {
                    layer.close(loading);
                    console.log(res);
                    addOrUpdate.$data.appName = res.appName;
                    console.log(addOrUpdate.$data.appName)
                    addOrUpdate.save();
                }).fail(function(res) {
                    layer.close(loading);
                    console.log("上传失败");
                });
            }else{
                this.save();
            }
        },
        save:function(){
            addOrUpdate.$data.codes = [];
            $.each(addOrUpdate.$data.checkPostions,function (i) {
                addOrUpdate.$data.codes[i] = addOrUpdate.$data.checkPostions[i].postionCode;
            });
            console.log(addOrUpdate.$data)
            var actionUrl=this.id=="" ? 'save' :'update';
            this.$data["postionCodeList"] = JSON.stringify(addOrUpdate.$data.codes);
            this.$http.post(pageUrl + actionUrl,this.$data).then(function(response){
                //显示成功或失败信息
                var isSuccess=customUtils.showTips(response.body,addOrUpdate.$data,1000);
                if(actionUrl=='update'){
                    var record = dataList.pageInfo.list[dataList.selectedIdx];
                    //更新成功，刷新列表中对应的数据
                    $.each(record, function(key) {
                        if(addOrUpdate[key]!=undefined){
                            record[key]=addOrUpdate[key];
                        }
                    });
                }else if(isSuccess){
                    if(response.body.versionError!=''&& response.body.versionError != null){
                        customUtils.tips(response.body.versionError,5,3000);
                    }else{customUtils.tips('操作成功',1,2000);}
                }
                dataList.getList('no');
                if(isSuccess && addPanel)layer.close(addPanel);
            },function(res){
                console.log(response.body);
            });
        },
        cancel:function(){
            if(addPanel)layer.close(addPanel);
        }
    }
});
//新增或更新---------end-------

var showVue = new Vue({
    el:"#showPanel",
    data:{
        provinces:[],

    },
    methods:{
        showPostions:function (record) {
            console.log(showVue.$data)
            layer.open({
                type : 1,
                title : "app更新区域/位置",
                area : [ '570px', '300px' ],
                shadeClose : false, // 点击遮罩关闭
                content : $('#showPanel')
            });
        }

    }
});

//新增或更新---------end-------

var importVue = new Vue({
    el:"#importPanel",
    data:{
        filedErr:"",
        appVersionId:""
    },
    methods:{
        importB:function () {
            var self = this;
            if(!dictType.checkFileType()){
                return;
            }
            console.log($("#importPanel"))
            console.log($("#importPanel").find("#filed")[0].files)
            var formDate = new FormData($("#importPanel")[0]);
            //没选择文件时
            if($("#importPanel").find("#filed")[0].files.length <= 0){
                $(".errMsg").html("请选择要上传的数据文件");
                return;
            }
            customUtils.post(self,pageUrl + "appUpload",formDate,function (response) {
                console.log(response);
                customUtils.showTips(response.body,null,2000);
                var html = "";
                if(response.body.errList != 'undefined' && response.body.errList != '' && response.body.errList != null){
                    response.body.errList.forEach(function (value, index) {
                        html = html + value + "<br>";
                    });
                    $(".errMsg").html(html);
                }else{
                    if(importPanel)layer.close(importPanel);
                    dataList.getList('init');
                }
            },function (response) {
                customUtils.showRequestTips(response,3000)
            })
            console.log(formDate);
        }
    }
});

// 更新APP版本号
var importPanelVue = new Vue({
    el: "#importPanel1",
    data: {
        filedErr: "",
        appVersionId: ""
    },
    methods: {
        importA: function () {
            var self = this;
            console.log($("#importPanel1"))
            console.log($("#importPanel1").find("#filed1")[0].files)
            var formDate = new FormData($("#importPanel1")[0]);
            //没选择文件时
            if ($("#importPanel1").find("#filed1")[0].files.length <= 0) {
                $(".errMsg").html("请选择要上传的数据文件");
                return;
            }
            customUtils.post(self, pageUrl + "appVersion", formDate, function (response) {
                console.log(response);
                customUtils.showTips(response.body, null, 2000);
                var html = "";
                if (response.body.errList != 'undefined' && response.body.errList != '' && response.body.errList != null) {
                    response.body.errList.forEach(function (value, index) {
                        html = html + value + "<br>";
                    });
                    $(".errMsg").html(html);
                } else {
                    if (importPanel1) layer.close(importPanel1);
                    dataList.getList('init');
                }
            }, function (response) {
                customUtils.showRequestTips(response, 3000)
            })
            console.log(formDate);
        }
    }
});


// 更新APP版本号
var importPanelListVue = new Vue({
    el: "#importPanel2",
    data: {
        filedErr: "",
        appVersionId: ""
    },
    methods: {
        importC: function () {
            var self = this;
            console.log($("#importPanel2"))
            console.log($("#importPanel2").find("#filed2")[0].files)
            var formDate = new FormData($("#importPanel2")[0]);
            //没选择文件时
            if ($("#importPanel2").find("#filed2")[0].files.length <= 0) {
                $(".errMsg").html("请选择要上传的数据文件");
                return;
            }
            customUtils.post(self, pageUrl + "appVersionList", formDate, function (response) {
                console.log(response);
                customUtils.showTips(response.body, null, 2000);
                var html = "";
                if (response.body.errList != 'undefined' && response.body.errList != '' && response.body.errList != null) {
                    tips(response.body.errList,5)
                } else {
                    if (importPanel2) layer.close(importPanel2);
                    dataList.getList('init');
                    customUtils.tips('操作成功',1,2000);
                }
            }, function (response) {
                customUtils.showRequestTips(response, 3000)
            })
            console.log(formDate);
        }
    }
});

// 更新APP版本号
var importUpdatePanelListVue = new Vue({
    el: "#importPanel3",
    data: {
        filedErr: "",
        appVersionId: ""
    },
    methods: {
        importD: function () {
            var self = this;
            console.log($("#importPanel3"))
            console.log($("#importPanel3").find("#filed3")[0].files)
            var formDate = new FormData($("#importPanel3")[0]);
            //没选择文件时
            if ($("#importPanel3").find("#filed3")[0].files.length <= 0) {
                $(".errMsg").html("请选择要上传的数据文件");
                return;
            }
            customUtils.post(self, pageUrl + "appUpdateVersionList", formDate, function (response) {
                console.log(response);
                customUtils.showTips(response.body, null, 2000);
                var html = "";
                if (response.body.errList != 'undefined' && response.body.errList != '' && response.body.errList != null) {
                    tips(response.body.errList,5)
                } else {
                    if (importPanel3) layer.close(importPanel3);
                    dataList.getList('init');
                    customUtils.tips('操作成功',1,2000);
                }
            }, function (response) {
                customUtils.showRequestTips(response, 3000)
            })
            console.log(formDate);
        }
    }
});


// 更新APP版本号
var importFirmwarePanelListVue = new Vue({
    el: "#importPanel4",
    data: {
        filedErr: "",
        appVersionId: ""
    },
    methods: {
        importE: function () {
            var self = this;
            console.log($("#importPanel4"))
            console.log($("#importPanel4").find("#filed4")[0].files)
            var formDate = new FormData($("#importPanel4")[0]);
            //没选择文件时
            if ($("#importPanel4").find("#filed4")[0].files.length <= 0) {
                $(".errMsg").html("请选择要上传的数据文件");
                return;
            }
            customUtils.post(self, pageUrl + "appUpdateFirmwareList", formDate, function (response) {
                console.log(response);
                customUtils.showTips(response.body, null, 2000);
                var html = "";
                if (response.body.errList != 'undefined' && response.body.errList != '' && response.body.errList != null) {
                    tips(response.body.errList,5)
                } else {
                    if (importPanel4) layer.close(importPanel4);
                    dataList.getList('init');
                    customUtils.tips('操作成功',1,2000);
                }
            }, function (response) {
                customUtils.showRequestTips(response, 3000)
            })
            console.log(formDate);
        }
    }
});